package org.jeecg.modules.common.config;

import com.github.lianjiatech.retrofit.spring.boot.interceptor.BasePathMatchInterceptor;
import okhttp3.Credentials;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Component;

import java.io.IOException;
@Component
public class OkhttpSignInterceptor extends BasePathMatchInterceptor {

    private String basicUser;

    private String basicPassword;


    public void setBasicUser(String basicUser) {
        this.basicUser = basicUser;
    }


    public void setBasicPassword(String basicPassword) {
        this.basicPassword = basicPassword;
    }

    @Override
    public Response doIntercept(Chain chain) throws IOException {
        String credential = Credentials.basic(basicUser, basicPassword);
        Request request = chain.request();
        Request newReq = request.newBuilder()
                .addHeader("Authorization", credential)
                .build();
        return chain.proceed(newReq);
    }
}